//
//  BJRewardAginPopView.m
//  BowJoy
//
//  Created by  on 2024/5/20.
//

#import "BJRewardAginPopView.h"

static CGFloat leftMain = 60;//白色背景离左右距离
@interface BJRewardAginPopView()
@property (nonatomic,strong) UIView *bottomPopView;
@property (nonatomic,assign) CGFloat bottomPopViewHeight;//视图的高度
 @property (nonatomic,strong)UIImageView *rowIcon;
@property (nonatomic,strong)UILabel *topLabel;
@property (nonatomic,strong)UILabel *decLabel;
@property (nonatomic,strong)UIButton *laterBtn;
@property (nonatomic,strong)UIImageView *bgImageBView;
@property (nonatomic)NSString *title;
@property (nonatomic)NSString *content;


@end

@implementation BJRewardAginPopView

- (instancetype)initWithTitle:(NSString *)title andContent:(NSString *)content{
    self = [super init];
    if (self) {
        self.title = title;
        self.content = content;
        [self initSubViews];
    }
    return self;
}
-(void)initSubViews{
    
    self.bottomPopViewHeight = kScreenH -120;

    [self addSubview:self.bottomPopView];
    self.bottomPopView.makeCons(^{
        make.left.constants(leftMain);
        make.right.constants(-leftMain);
        make.center.constants(0);
    });
    
    [self.bottomPopView addSubview:self.bgImageBView];
    self.bgImageBView.makeCons(^{
        make.edge.constants(0);
    });


    [self.bottomPopView addSubview:self.topLabel];
    self.topLabel.makeCons(^{
        make.leading.constants(10);
        make.trailing.constants(-10);
        make.top.view(self.bottomPopView).constants(20);
    });

    [self.bottomPopView addSubview:self.rowIcon];
    self.rowIcon.makeCons(^{
        make.top.view(self.topLabel).bottom.constants(16);
        make.centerX.constants(0);
        make.width.constants(139);
        make.height.constants(132);

    });
    
    
    [self.bottomPopView addSubview:self.decLabel];
    self.decLabel.makeCons(^{
        make.leading.constants(23);
        make.trailing.constants(-23);
        make.top.view(self.rowIcon).bottom.constants(10);
    });
    
    
    [self.bottomPopView addSubview:self.laterBtn];
    self.laterBtn.makeCons(^{
        make.centerX.constants(0);
        make.top.view(self.decLabel).bottom.constants(10);
        make.width.constants(126);
        make.height.constants(40);
        make.bottom.constants(-20);
    });
    
  
}

-(void)showView{
    self.frame = [UIScreen mainScreen].bounds;
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.backgroundColor = PopViewBackColor;
}

#pragma mark - 点击背景关闭视图
-(void)closeView
{
    if(self.updateOKBack){
        self.updateOKBack();
    }
    [self removeFromSuperview];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}

-(void)agreeBtnClick{
    
    
}

-(UIImageView *)bgImageBView
{
    if (_bgImageBView == nil) {
        _bgImageBView = [[UIImageView alloc]init];
        _bgImageBView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImageBView.userInteractionEnabled = YES;
        _bgImageBView.image = [UIImage imageNamed:@"icon_home_pop_rewardAgainBg"];
    }
    return _bgImageBView;
}


-(UIView *)bottomPopView
{
    if (_bottomPopView == nil) {
        _bottomPopView = [[UIView alloc] init];
        _bottomPopView.backgroundColor = [UIColor whiteColor];
        _bottomPopView.layer.cornerRadius = 12;
        _bottomPopView.layer.masksToBounds = YES;
    }
    return _bottomPopView;
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}

 
-(UIImageView *)rowIcon
{
    if (_rowIcon == nil) {
        _rowIcon = [[UIImageView alloc]init];
        _rowIcon.image = [UIImage imageNamed:@"icon_home_pop_rewardAgain"];
    }
    return _rowIcon;
}

-(UILabel *)decLabel
{
    if (_decLabel == nil) {
        _decLabel = [[UILabel alloc]init];
        _decLabel.textColor = [UIColor colorWithHexString:@"#666666"];
        _decLabel.font = [UIFont systemFontOfSize:16];
        _decLabel.textAlignment = NSTextAlignmentCenter;
        _decLabel.text = self.content;

        _decLabel.numberOfLines = 0;
    }
    return _decLabel;
}
-(UILabel *)topLabel
{
    if (_topLabel == nil) {
        _topLabel = [[UILabel alloc]init];
        _topLabel.textColor =  [UIColor colorWithHexString:@"#000000"];
        _topLabel.textAlignment = NSTextAlignmentCenter;
        _topLabel.font = [UIFont fontWithName:@"Arial Black"size:20];
        _topLabel.text = self.title;

    }
    return _topLabel;
}


-(UIButton *)laterBtn
{
    if (_laterBtn == nil) {
        _laterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_laterBtn setBackgroundImage:[UIImage imageNamed:@"icon_home_ok"] forState:UIControlStateNormal];
        [_laterBtn addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _laterBtn;
}

@end
